﻿using IHC.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace IHC.Controllers
{
    public class HomeController : Controller
    {
        private Usuarios db= new Usuarios();


        [HttpPost]
        public ActionResult Access(string numero, string clave)
        {
            DbSet<UserAccess> acceso = db.UserAccess;
            bool finded = acceso.Any(ua =>
                  ua.Account == numero
                  && ua.Password == clave
            );
            if (finded)
                return View();
            else
            {
                ViewBag.WasFound = false;
                return View("Index");
            }
        }

        public ActionResult Forget()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Forget(string email)
        {
            DbSet<UserData> data = db.UserData;
            bool finded = data.Any(ud => ud.Email == email);
            
            if (finded)
            {
                ViewBag.WasFound = true;
            }
            else
            {
                ViewBag.WasFound = false;
            }
           return View();
        }

        public ActionResult Index()
        {

            return View();
        }


        public ActionResult Register()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Register(FormCollection form)
        {
            db.UserAccess.Add(new UserAccess { Account = form["cuenta"], Password = form["clave"] });
            db.UserData.Add(new UserData
            {
                Account = form["cuenta"],
                Name = form["nombre"],
                PatSurname = form["appat"],
                MatSurname = form["apmat"],
                Email = form["email"]
            });
            db.SaveChanges();
            return View("Successfull");
        }
    }
}